import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SGuildEliteCopyDetail } from "../../../../../Message/Public/SGuildEliteCopyDetail";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GuildEliteConfig } from "../config/GuildEliteConfig";
import { EliteTowerMapData } from "../config/info/EliteTowerMapData";
import { BossConfig } from "../../../resource/BossConfig";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { BaseSkillItem } from "../../common/item/BaseSkillItem";
import { Cache } from "../../../cache/Cache";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
import { MsgManager } from "../../../manager/MsgManager";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class GuildEliteCopyCondition
    
    export  class GuildEliteCopyCondition extends GSprite
    {
        constructor()
        {
            super();
            this._bossVec = new Vector.<GTextFiled>();
            this._desc = ObjCreate.createGTextField("", 0, 0, 240, 20, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 5));
            this._desc.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._desc.wordWrap = true;
            this._desc.mouseWheelEnabled = false;
            this._desc.addEventListener(flash.events.TextEvent.LINK, this.onTextClickHandler);
            return;
        }

        public updateData(arg1: Boolean, arg2: SGuildEliteCopyDetail): void
        {
            if (arg1) 
            {
                this._isHell = arg1;
                this._data = arg2;
                this.clearAll();
                this._desc.htmlText = this.getConditionHell(arg2);
                this._outHeight = this._desc.textHeight;
            }
            else if (this._data && this._data.copyCode == arg2.copyCode && this._data.mapId == arg2.mapId && this._isHell == arg1) 
            {
                this._isHell = arg1;
                this._data = arg2;
                this.updateBossesStatus(arg2);
            }
            else 
            {
                this._isHell = arg1;
                this._data = arg2;
                this.clearAll();
                this.initBossesCondition(arg2);
            }
            return;
        }

        /* internal  */getConditionHell(arg1: SGuildEliteCopyDetail): string
        {
            var loc4=null;
            var loc1=HTMLUtil.addColor(Language.getString(60619), GlobalStyle.color1) + "\n";
            var loc2=GuildEliteConfig.instance.getFloorByCopycode(arg1.copyCode);
            var loc3=GuildEliteConfig.instance.getMapsByFloor(loc2);
            var loc5=0;
            while (loc5 < loc3.length) 
            {
                if ((loc4 = loc3[loc5] as EliteTowerMapData).completed) 
                {
                    loc1 = loc1 + (HTMLUtil.addColor(loc4.name + "    \t" + Language.getString(60621), "#727B78") + "\n");
                }
                else 
                {
                    loc1 = loc1 + (HTMLUtil.addColor("<a href=\'event:" + loc4.map + "\'><u>" + loc4.name + "</u></a>    \t" + Language.getString(60620), GlobalStyle.color5) + "\n");
                }
                ++loc5;
            }
            return loc1;
        }

        /* internal  */initBossesCondition(arg1: SGuildEliteCopyDetail): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc8=null;
            var loc9=null;
            var loc10=0;
            this._outHeight = 0;
            this._desc.htmlText = HTMLUtil.addColor(Language.getString(60624), GlobalStyle.color1);
            this._outHeight = this._outHeight + (this._desc.textHeight + 2);
            var loc1=GuildEliteConfig.instance.getMap(arg1.copyCode, arg1.mapId);
            if (loc1) 
            {
                loc2 = loc1.getBosses();
                loc7 = 0;
                while (loc7 < loc2.length) 
                {
                    if (loc6 = BossConfig.instance.getInfoByCode(parseInt(loc2[loc7]))) 
                    {
                        if (arg1.bossInfo[loc6.code]) 
                        {
                            loc8 = HTMLUtil.addColor(loc6.boss.name + "\t" + parseInt(arg1.bossInfo[loc6.code]) + "/1", "#727B78") + "\n";
                        }
                        else 
                        {
                            loc8 = HTMLUtil.addColor(loc6.boss.name + "\t" + "0/1", GlobalStyle.color1) + "\n";
                        }
                        loc9 = ObjCreate.createGTextField(loc8, 10, this._outHeight, 200, 20, this, null, true, false);
                        this._bossVec.push(loc9);
                        this._outHeight = this._outHeight + (loc9.textHeight + 10);
                        if ((loc3 = loc1.getShowSkillsByBoss(parseInt(loc2[loc7]))) && loc3.length > 0) 
                        {
                            loc10 = 0;
                            while (loc10 < loc3.length) 
                            {
                                loc4 = loc3[loc10] as TSkill;
                                (loc5 = UICompomentPool.getUICompoment(BaseSkillItem)).skill = loc4;
                                loc5.setSize(32, 32);
                                loc5.x = 13 + loc10 * 45;
                                loc5.y = this._outHeight;
                                this.addChild(loc5);
                                ++loc10;
                            }
                            this._outHeight = this._outHeight + 38;
                        }
                    }
                    ++loc7;
                }
            }
            return;
        }

        /* internal  */updateBossesStatus(arg1: SGuildEliteCopyDetail): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc1=GuildEliteConfig.instance.getMap(arg1.copyCode, arg1.mapId);
            if (loc1) 
            {
                loc2 = loc1.getBosses();
                loc4 = 0;
                while (loc4 < loc2.length) 
                {
                    if (loc3 = BossConfig.instance.getInfoByCode(parseInt(loc2[loc4]))) 
                    {
                        if (arg1.bossInfo[loc3.code]) 
                        {
                            loc5 = HTMLUtil.addColor(loc3.boss.name + "\t" + parseInt(arg1.bossInfo[loc3.code]) + "/1", "#727B78") + "\n";
                        }
                        else 
                        {
                            loc5 = HTMLUtil.addColor(loc3.boss.name + "\t" + "0/1", GlobalStyle.color1) + "\n";
                        }
                        this._bossVec[loc4].htmlText = loc5;
                    }
                    ++loc4;
                }
            }
            return;
        }

        /* internal  */clearAll(): void
        {
            var loc1=null;
            var loc2=(this.numChildren - 1);
            while (loc2 >= 0) 
            {
                loc1 = this.getChildAt(loc2);
                if (loc1 != this._desc) 
                {
                    UICompomentPool.disposeUICompoment(loc1);
                }
                --loc2;
            }
            this._bossVec = new Vector.<GTextFiled>();
            return;
        }

        public /* override */ get height(): number
        {
            return this._outHeight;
        }

        /* internal  */onTextClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=parseInt(arg1.text);
            var loc2=Cache.instance.scene.getPassPointByToMapId(loc1);
            if (loc2) 
            {
                AIManager.onAutoPathAIControl(loc2, AIType.AI_Scene);
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(60628));
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            this.clearAll();
            this._data = null;
            return;
        }

        /* internal */ /* var */_desc: GTextFiled;

        /* internal */ /* var */_bossVec: Vector.<GTextFiled>;

        /* internal */ /* var */_isHell: Boolean;

        /* internal */ /* var */_data: SGuildEliteCopyDetail;

        /* internal */ /* var */_outHeight: int;
    }
